import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-08-27
 * Time: 15:30
 */
public class Test {
    public static int lengthOfLongestSubstring1(String s) {
        if(s.length() == 0) return 0;
        if(s.length() == 1) return 1;
        String str = "";
        Map<String,Integer> map = new HashMap<>();
        for(int i = 0;i < s.length();i++){
            char ch = s.charAt(i);

            //判段str里是包含该字符
            if(str.contains(ch + "")){
                //将无重复字符串及其长度大小作为键值对放入map
                map.put(str,str.length());
                str = "";
            }
            str += ch;
        }
        if(str != ""){
            map.put(str,str.length());
        }
        //返回map最大val
        Collection<Integer> coll = map.values();
        int max = 0;
        for(Integer e : coll){
            if(max < e) max = e;
        }
        return max;
    }
    public static int lengthOfLongestSubstring(String s) {
        if(s.length() == 0 ) return 0;
        if(s.length() == 1 ) return 1;
        String str = "";
        int max = 0;
        for(int i = 0;i < s.length();i++){
            int count = 0;
            for(int j = i;j < s.length();j++){
                char ch = s.charAt(j);
                //判段str里是包含该字符
                if(str.contains(ch + "")){
                    if(count > max) max = count;
                    str = "";
                    break;
                }
                str += ch;
                count++;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        String str = "au";
        int ret = lengthOfLongestSubstring(str);
        System.out.println(ret);
    }
}
